//
//  EAGLView.h
//  icamera
//
//  Created by Berlin Brown on 9/2/09.
//  Copyright __MyCompanyName__ 2009. All rights reserved.
//

#import <UIKit/UIKit.h>
#import <OpenGLES/EAGL.h>
#import <OpenGLES/ES1/gl.h>
#import <OpenGLES/ES1/glext.h>

#define DEGREES_TO_RADIANS(__ANGLE__) ((__ANGLE__) / 180.0 * M_PI)

@protocol GLOctaneMechViewDelegate;

/*
This class wraps the CAEAGLLayer from CoreAnimation into a convenient UIView subclass.
The view content is basically an EAGL surface you render your OpenGL scene into.
Note that setting the view non-opaque will only work if the EAGL surface has an alpha channel.
*/
@interface EAGLView : UIView {
    
@private

    /* The pixel dimensions of the backbuffer */
    GLint backingWidth;
    GLint backingHeight;
    
    EAGLContext *context;
    
    /* OpenGL names for the renderbuffer and framebuffers used to render to this view */
    GLuint viewRenderbuffer, viewFramebuffer;
    
    /* OpenGL name for the depth buffer that is attached to viewFramebuffer, if it exists (0 if it does not exist) */
    GLuint depthRenderbuffer;
    
    NSTimer *animationTimer;
    NSTimeInterval animationInterval;

	// Delegate to do our drawing, called by -drawView, which can be called manually or via the animation timer.
	id<GLOctaneMechViewDelegate> delegate;

	// Flag to denote that the -setupView method of a delegate has been called.
	// Resets to NO whenever the delegate changes.
	BOOL delegateSetup;

	CGPoint location;
	CGPoint previousLocation;
	Boolean firstTouch;

} // End of UIView //

@property(nonatomic, readwrite) CGPoint location;
@property(nonatomic, readwrite) CGPoint previousLocation;

@property(nonatomic, assign) id<GLOctaneMechViewDelegate> delegate;

-(void)startAnimation;
-(void)stopAnimation;
-(void)drawView;

@property NSTimeInterval animationInterval;

@end

/////////////////////////////////////////////////////////////////////

@protocol GLOctaneMechViewDelegate<NSObject>

@required

// Draw with OpenGL ES
-(void)drawView:(EAGLView*)view;

@optional

// Called whenever you need to do some initialization before rendering.
-(void)setupView:(EAGLView*)view;

@end




